using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace FanaticGene.AvaloniaMaid.Core.Helpers
{
    public static class StyleHelper
    {
        public static async Task<MatchCollection> GetStylesAsync(string file)
        {
            using var fs = File.OpenRead(file);
            return await GetStylesAsync(fs);
        }

        public static async Task<MatchCollection> GetStylesAsync(Stream fs)
        {
            using var textReader = new StreamReader(fs);
            var text = await textReader.ReadToEndAsync();

            var pattern = "<Style.*?Selector=\".*? <\\/Style>";
            var results = Regex.Matches(text, pattern, RegexOptions.Singleline);

            return results;
        }
    }
}
